package com.icebartech.core.utils;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.icebartech.core.constants.IcebartechConstants;

public class CommonUtil {
	
	/**
	 * 验证密码或用户名格式是否正确
	 * @param password
	 *            密码
	 * @return
	 */
	public static boolean verifyPassword(String password) {
		if (StringUtils.isNotEmpty(password)) {
			return password.matches("^[A-Za-z0-9]{6,20}$");
		}
		return false;
	}

    public final static String MD5(String s) {
        char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};       
        try {
            byte[] btInput = s.getBytes("UTF-8");
            // 获得MD5摘要算法的 MessageDigest 对象
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            // 使用指定的字节更新摘要
            mdInst.update(btInput);
            // 获得密文
            byte[] md = mdInst.digest();
            // 把密文转换成十六进制的字符串形式
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

	public static String pwdMd5(String userPwd, String userPwd2) {
		return MD5((MD5(userPwd)
				+ userPwd2 + "dingfanhe@^&*%$#!%^"));
	}

	public static boolean validatePwdMD5(String matchPwd, String password,
			String matchPwd2) {
		return (!(matchPwd.equals(pwdMd5(password, matchPwd2))));
	}
	
	/**
	 * 获取单位列表
	 * @return
	 */
	public static List<String> getItemUnitList(){
		List<String> rtnList = new ArrayList<String>();
		rtnList.add("份");
		rtnList.add("斤");
		rtnList.add("只");
		rtnList.add("条");
		return rtnList;
	}
	
	/**
	 * 获取类别类型Map
	 * @return
	 */
	public static Map<Integer, String> getCategoryTypeList(){
		Map<Integer, String> rtnMap = new HashMap<Integer, String>();
		rtnMap.put(1, "普通");
		rtnMap.put(2, "生鲜类");
		rtnMap.put(3, "特殊");
		return rtnMap;
	}
	
	/**
	 * 获取日期类型集合
	 * @return
	 */
	public static List<Map<String, Object>> getDateSourceList(){
		List<Map<String, Object>> rtnList = new ArrayList<Map<String,Object>>();
		String nowDate = DateTimeUtility.dateofnow();
		String oneDay = DateTimeUtility.addDate(nowDate, "D", 1);
		String twoDay = DateTimeUtility.addDate(nowDate, "D", 2);
		String threeDay = DateTimeUtility.addDate(nowDate, "D", 3);
		String fourDay = DateTimeUtility.addDate(nowDate, "D", 4);
		String fiveDay = DateTimeUtility.addDate(nowDate, "D", 5);
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", nowDate);
		rtnMap.put("value", nowDate);
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", oneDay);
		rtnMap.put("value", oneDay);
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", twoDay);
		rtnMap.put("value", twoDay);
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", threeDay);
		rtnMap.put("value", threeDay);
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", fourDay);
		rtnMap.put("value", fourDay);
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", fiveDay);
		rtnMap.put("value", fiveDay);
		rtnList.add(rtnMap);
		return rtnList;
	}
	
	/**
	 * 获取时间类型集合
	 * @return
	 */
	public static List<Map<String, Object>> getTimeSourceList(){
		List<Map<String, Object>> rtnList = new ArrayList<Map<String,Object>>();
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "07:00-09:00");
		rtnMap.put("value", "07:00-09:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "09:00-11:00");
		rtnMap.put("value", "09:00-11:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "11:00-13:00");
		rtnMap.put("value", "11:00-13:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "13:00-15:00");
		rtnMap.put("value", "13:00-15:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "15:00-17:00");
		rtnMap.put("value", "15:00-17:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "17:00-19:00");
		rtnMap.put("value", "17:00-19:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "19:00-21:00");
		rtnMap.put("value", "19:00-21:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "21:00-23:00");
		rtnMap.put("value", "21:00-23:00");
		rtnList.add(rtnMap);
		rtnMap = new HashMap<String, Object>();
		rtnMap.put("key", "23:00-01:00");
		rtnMap.put("value", "23:00-01:00");
		rtnList.add(rtnMap);
		return rtnList;
	}
	
	public static Map<Integer, String> getDispatchTimeMap(){
		String nowDate = DateTimeUtility.dateofnow();
		String time1Start = nowDate + " 11:30:00";
		String time1End = nowDate + " 12:30:00";
		String time2Start = nowDate + " 15:00:00";
		String time2End = nowDate + " 16:00:00";
		String time3Start = nowDate + " 17:30:00";
		
		long time1StartLong = DateTimeUtility.getTransTime(time1Start);
		long time1EndLong = DateTimeUtility.getTransTime(time1End);
		long time2StartLong = DateTimeUtility.getTransTime(time2Start);
		long time2EndLong = DateTimeUtility.getTransTime(time2End);
		long time3StartLong = DateTimeUtility.getTransTime(time3Start);
		
		long currenTimestamp = DateTimeUtility.getTradeSn();
		
		Map<Integer, String> rtnMap = new HashMap<Integer, String>();
		if(currenTimestamp < time1StartLong){
			rtnMap.put(1, nowDate + " 11:30-12:30");
			rtnMap.put(2, nowDate + " 15:00-16:00");
			rtnMap.put(3, nowDate + " 17:30-18:30");
		}else if(currenTimestamp > time1EndLong && currenTimestamp < time2StartLong){
			rtnMap.put(2, nowDate + " 15:00-16:00");
			rtnMap.put(3, nowDate + " 17:30-18:30");
		}else if(currenTimestamp > time2EndLong && currenTimestamp < time3StartLong){
			rtnMap.put(3, nowDate + " 17:30-18:30");
		}else{
			String nextDay = DateTimeUtility.addDate(nowDate, "D", 1);
			rtnMap.put(4, nextDay + " 11:30-12:30");
			rtnMap.put(5, nextDay + " 15:00-16:00");
			rtnMap.put(6, nextDay + " 17:30-18:30");
		}
		return rtnMap;
	}
	
	/**
	 * 根据dispatchTime值转换时间格式的字符串
	 * @param timeInt
	 * @return
	 */
	public static String getDispatchTimeSchedule(Date createDate, Integer timeInt){
		Map<Integer, String> rtnMap = new HashMap<Integer, String>();
		String nowDay = DateTimeUtility.dateofnow(createDate);
		String nextDay = DateTimeUtility.addDate(nowDay, "D", 1);
		rtnMap.put(1, nowDay + " 11:30-12:30");
		rtnMap.put(2, nowDay + " 15:00-16:00");
		rtnMap.put(3, nowDay + " 17:30-18:30");
		rtnMap.put(4, nextDay + " 11:30-12:30");
		rtnMap.put(5, nextDay + " 15:00-16:00");
		rtnMap.put(6, nextDay + " 17:30-18:30");
		return rtnMap.get(timeInt);
	}
	
	/**
	 * 微派到家积分-人民币兑换规则
	 * @param pointCount
	 * @return
	 */
	public static double weiPaiPointCountRule(Double pointCount){
		double rtnAmount = 0.0;
		if(pointCount != null && pointCount > 0.0){
			NumberFormat numberFormat = NumberFormat.getNumberInstance();
			numberFormat.setMaximumFractionDigits(1);
			double point = pointCount / 100;
			rtnAmount = Double.valueOf(numberFormat.format(point));
		}
		return rtnAmount;
	}
	
	/**
	 * 微派到家人民币-积分兑换规则
	 * @param pointCount
	 * @return
	 */
	public static double weiPaiAmountRule(Double amount){
		double rtnPointCount = 0.0;
		if(amount != null && amount > 0.0){
			rtnPointCount = amount;
		}
		return rtnPointCount;
	}
	
	/**
	 * 英农积分兑换规则
	 * @param pointCount
	 * @return
	 */
	public static double innofarmPointCountRule(Double pointCount){
		double rtnAmount = 0.0;
		if(pointCount != null && pointCount > 0.0){
			NumberFormat numberFormat = NumberFormat.getNumberInstance();
			numberFormat.setMaximumFractionDigits(1);
			double point = pointCount / 100;
			rtnAmount = Double.valueOf(numberFormat.format(point));
		}
		return rtnAmount;
	}
	
	/**
	 * 把数组按照“参数=参数值”的模式用“&”字符拼接成字符串
	 * @param paramMap
	 * @return
	 */
	public static String createLinkString(Map<String, Object> paramMap){
		List<String> keys = new ArrayList<String>(paramMap.keySet());
		
		StringBuffer rtnStr = new StringBuffer();
		for(int i = 0; i < keys.size(); i++){
			String key = keys.get(i);
			Object value = paramMap.get(key);
			if(i == keys.size() - 1){
				rtnStr.append(key + "=" + value);
			}else{
				rtnStr.append(key + "=" + value + "&");
			}
		}
		return rtnStr.toString();
	}
	
	/**
	 * byte数组转换为char数组
	 * @param bytes
	 * @return
	 */
	public static char[] getChars (byte[] bytes) {
		Charset cs = Charset.forName("UTF-8");
		ByteBuffer bb = ByteBuffer.allocate(bytes.length);
		bb.put(bytes);
		bb.flip();
		CharBuffer cb = cs.decode(bb);
		return cb.array();
	}

	/**
	 * char数组转换为byte数组
	 * @param chars
	 * @return
	 */
	public static byte[] getBytes (char[] chars) {
		Charset cs = Charset.forName("UTF-8");
		CharBuffer cb = CharBuffer.allocate(chars.length);
		cb.put(chars);
		cb.flip();
		ByteBuffer bb = cs.encode(cb);
		return bb.array();
	}
	
	/**
	 * 获取文件名的后缀
	 * @param fileName
	 * @return
	 */
	public static String getFileSuffix(String fileName){
		String rtn = null;
		if(StringUtils.isNotEmpty(fileName)){
			int index = fileName.lastIndexOf(".");
			if(index > -1){
				rtn = fileName.substring(index + 1);
			}
		}
		return rtn;
	}
	
	/**
	 * 判断是否没有设置过昵称
	 * @param userId 用户id 
	 * @param nickname 用户昵称
	 * @return
	 */
	public static boolean isHadSetNickname(Long userId, String nickname){
		boolean flag = false;
		if(userId != null && userId > 0 && StringUtils.isNotBlank(nickname)){
			flag = !("用户" + userId).equals(nickname);
		}
		return flag;
	}
	
	/**
	 * 获取真实的分表表名后缀，格式如：_xxxx，会用leftPad来左补齐
	 * @param shardingId
	 * @param by
	 * @return
	 */
	public static String getShardingTableSuffix(long shardingId, int by){
		if(shardingId <= 0 || by <= 0){
			throw new RuntimeException("shardingId or by is invalid!");
		}else if(by > 1024){
			throw new RuntimeException("by should be less than 1024!");
		}
		//计算by是几位数
		int index = 1;
		int a = 0;
		int temp = by;
		while((a = temp / 10) > 0){
			index++;
			temp = a;
		}
		long realShardingId = shardingId % by;
		return "_" + StringUtils.leftPad(String.valueOf(realShardingId), index, '0');
	}
	
	
	/**
	 * 获取所有领域列表
	 */
	public static List<Map<String, Object>> getAppScopeList(){
		List<Map<String, Object>> appScopeList = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
		map.put("id", "wanli");
		map.put("text", "塘尾万里学校");
		appScopeList.add(map);
		
		//add others
		map = new HashMap<>();
		map.put("id", "qiaotou");
		map.put("text", "桥头小学");
		appScopeList.add(map);
		
		return appScopeList;
	}
	
	/**
	 * 根据id值解析给领域对应的中文描述信息
	 * @param id
	 * @return
	 */
	public static String parseAppScopeDesc(String id){
		String rtnStr = null;
		for(Map<String, Object> map : getAppScopeList()){
			if(map.get("id").toString().equals(id)){
				rtnStr = map.get("text").toString();
				break;
			}
		}
		return rtnStr;
	}

	
	/**
	 * doble保留两位小数格式化后返回
	 * @param val
	 * @return
	 */
	public static Double formatDouble2(Double val){
		DecimalFormat format = new DecimalFormat("#.00");
		String str = format.format(val);
		return Double.valueOf(str);
	}
	
	/**
	 * doble保留三位小数格式化后返回
	 * @param val
	 * @return
	 */
	public static Double formatDouble3(Double val){
		DecimalFormat format = new DecimalFormat("#.000");
		String str = format.format(val);
		return Double.valueOf(str);
	}
	/**
	 * doble保留四位小数格式化后返回
	 * @param val
	 * @return
	 */
	public static Double formatDouble4(Double val){
		DecimalFormat format = new DecimalFormat("#.0000");
		String str = format.format(val);
		return Double.valueOf(str);
	}
	
	/**
	 * double转百分比表示法
	 * @param val
	 * @return
	 */
	public static String getPercent(Double val){
		if(val == null){
			val = 0d;
		}
		DecimalFormat df = new DecimalFormat("###.00%");
		return df.format(val);
	}
	
	/**
	 * 简单转义html标签
	 * @param str
	 * @return
	 */
	public static String escapeHtmlSimple(String str){
		str = str.replaceAll("&", "&amp;");
		str = str.replaceAll("<", "&lt;");
		str = str.replaceAll(">", "&gt;");
		str = str.replaceAll("\"", "&quot;");
		return str;
	}
	
	/**
	 * 从字典map中根据value找到key
	 * @param dictMap
	 * @return
	 */
	public static String getKeyFromDictionary(Map<Long, String> dictMap, String value){
		String key = "";
		if(dictMap != null && dictMap.size() > 0 && StringUtils.isNotBlank(value)){
			for(Entry<Long, String> entry : dictMap.entrySet()){
				Long entryKey = entry.getKey();
				String entryValue = entry.getValue();
				if(entryValue.equals(value)){
					key = String.valueOf(entryKey);
				}
			}
		}
		return key;
	}
	
	/**
	 * 获取所有的系统字典项
	 * @return
	 */
	public static Map<String, String> getCodeTypeMap(){
		Map<String, String> dictMap = new HashMap<>();
		dictMap.put("country", "国家");
		dictMap.put("province", "省份");
		dictMap.put("city", "城市");
		dictMap.put("district", "地区");
		dictMap.put("occupation", "职业");
		dictMap.put("secondOccupation", "第二职业");
		dictMap.put("action", "爱好");
		dictMap.put("school", "学校");
		dictMap.put("sex", "性别");
		dictMap.put("nation", "民族");
		dictMap.put("civilState", "婚姻状况");
		dictMap.put("healthState", "健康状况");
		dictMap.put("politicalBackground", "政治面貌");
		dictMap.put("education", "学历");
		dictMap.put("educationLevel", "学位");
		dictMap.put("foreignLanType", "外语语种");
		dictMap.put("foreignLanLevel", "外语级别");
		dictMap.put("spokenLevel", "口语水平");
		dictMap.put("workYear", "工龄");
		dictMap.put("teachYear", "教龄");
		dictMap.put("computerLevel", "计算机水平");
		dictMap.put("topLevel", "最高职称");
		dictMap.put("topLevelType", "聘任性质");
		dictMap.put("nowLevel", "现聘职称");
		dictMap.put("jobStatus", "在职状态");
		dictMap.put("adminJob", "行政职务");
		dictMap.put("subject", "学科/岗位");
		dictMap.put("bloodType", "血型");
		dictMap.put("yOrN", "是/否");
		dictMap.put("studentType", "学生类型");
		dictMap.put("residenceType", "户口类型");
		dictMap.put("studentSource", "学生来源");
		dictMap.put("enterWay", "入学方式");
		dictMap.put("attendWay", "就读方式");
		dictMap.put("isColony", "港澳台侨");
		dictMap.put("attendStatus", "在校状态");
		dictMap.put("examStatus", "考试设置状态");
		dictMap.put("attendExamStatus", "参加考试状态");
		dictMap.put("examType", "考试类型");
		return dictMap;
	}
	
	/**
	 * 判断是否为低版本ie浏览器
	 * @param userAgent
	 * @return
	 */
	public static boolean isMSIE(String userAgent){
		if(StringUtils.isNotBlank(userAgent) && StringUtils.isNotBlank(userAgent) && userAgent.indexOf("MSIE") > -1 && userAgent.indexOf("Opera") < 0){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 通过userAgent来判断是微信的请求头
	 * @param userAgent
	 * @return
	 */
	public static boolean isMicroMessenger(String userAgent){
		if(StringUtils.isNotBlank(userAgent) && StringUtils.isNotBlank(userAgent) && userAgent.contains(IcebartechConstants.WEIXIN_USER_AGENT)){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断请求是否来自于手机端
	 * @param userAgent
	 * @return
	 */
	public static boolean isMobile(String userAgent){
		boolean isMoblie = false;
		String[] mobileAgents = { "iphone", "android", "phone", "mobile",  
				"wap", "netfront", "java", "opera mobi", "opera mini", "ucweb",  
				"windows ce", "symbian", "series", "webos", "sony",  
				"blackberry", "dopod", "nokia", "samsung", "palmsource", "xda",  
				"pieplus", "meizu", "midp", "cldc", "motorola", "foma",  
				"docomo", "up.browser", "up.link", "blazer", "helio", "hosin",  
				"huawei", "novarra", "coolpad", "webos", "techfaith",  
				"palmsource", "alcatel", "amoi", "ktouch", "nexian",  
				"ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui",  
				"smartphone", "iemobile", "spice", "bird", "zte-", "longcos",  
				"pantech", "gionee", "portalmmm", "jig browser", "hiptop",  
				"benq", "haier", "^lct", "320x320", "240x320", "176x220",  
				"w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq",  
				"bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang",  
				"doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi",  
				"keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo",  
				"midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-",  
				"newt", "noki", "oper", "palm", "pana", "pant", "phil", "play",  
				"port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-",  
				"send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar",  
				"sony", "sph-", "symb", "t-mo", "teli", "tim-", /*"tosh",*/ "tsm-",  
				"upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp",  
				"wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile", IcebartechConstants.WEIXIN_USER_AGENT};
		for (String mobileAgent : mobileAgents) {
			if (userAgent.toLowerCase().indexOf(mobileAgent.toLowerCase()) >= 0) {
                isMoblie = true;
                break;  
            }
		}
		return isMoblie;
	}
	
	/**
	 * 把对象转换成map对象
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> object2Map(Object obj){
		if(obj != null){
			return JSON.parseObject(JSON.toJSONString(obj));
		}
		return null;
	}
	
	/**
	 * 随机红包简单算法
	 * @param remainMoney 剩余的钱
	 * @param remainSize 剩余的红包数量
	 * @return
	 */
	public static double getRandomMoney(double remainMoney, int remainSize) {
	    // remainSize 剩余的红包数量
	    // remainMoney 剩余的钱
	    if (remainSize == 1) {
	        remainSize--;
	        return (double) Math.round(remainMoney * 100) / 100;
	    }
	    Random r     = new Random();
	    double min   = 0.01; 
	    double max   = remainMoney / remainSize * 2;
	    double money = r.nextDouble() * max;
	    money = money <= min ? 0.01: money;
	    money = Math.floor(money * 100) / 100d;
	    remainSize--;
	    // remainMoney -= money;
	    return money;
	}
	
	/**
     * 将手机密码处理成135...1067的形式
     * @param str
     * @return
     */
    public static String encodeMobile(String str) {
        if (StringUtils.isBlank(str) || str.length() != 11) {
            return str;
        }

        StringBuilder builder = new StringBuilder(11);
        builder.append(str.substring(0, 3));
        builder.append("...");
        builder.append(str.substring(7));

        return builder.toString();
    }
	
	public static void main(String[] args) throws Exception{
//		String              leftSeq             = StringUtils.leftPad(StringUtils.right("112312",4), 4, '0');
//		System.out.println(leftSeq);
		/*
		System.out.println(RandomStringUtils.randomAlphanumeric(16));
		Double result = ArithmeticUtils.div(2.0, 4.0, 2);
		System.out.println(result);
		*/
		/*
		String str = "巴拉拉小魔仙";
		String result1 = Cn2PinyinUtil.converter2Pinyin(str);
		String str2 = "巴啦啦小魔仙";
		String result2 = Cn2PinyinUtil.converter2Pinyin(str2);
		
		System.out.println(result1 + ", " + result2);
		*/
//		StringBuilder sb = new StringBuilder();
//		
//		String string = String.format("(select * from ErpOrder where isDeleted='n' %1$s)", sb.toString());
		System.out.println(RandomStringUtils.randomAlphanumeric(16).toLowerCase());
		String str = DesCrypto.decrypt("6d5b9b45f975538f", "va2tqalskxcuzjv8");
		System.out.println(str);
		
		List<String> dataList = new ArrayList<>();
		dataList.add("123");
		dataList.add(null);
		dataList.add("234");
		System.out.println("size:" + dataList.size());
		System.out.println(dataList.get(1) == null);
		
		
//		String  encryptedData = "yUNot+0IWHO3vvEXtps6iEuTwAZlAsp13J7omhpjDRMb76v4CW9QVwBlmYsIHip7Ohic94M5/mJZBVRkY/M3dMD7r3HXzAVdDkfrFUkucJ9hYt1JpOY6BqgOUp0qdMRrmpQxrlYnst2utEwtGluPGfF+eUGSQoX42jtv63dnUzfSueYOZVULWPG0XrGj01brdKUlHtmXz/FPLvFBVuKTIjYiaAILDzan3ILM4m0Sb/7SnZcWQTqd2erZT4HEklLEB+PdLiYM2qgUM9A/Ogsc/RWD/YQ5IbC0qJZoaXmPl06h5m1Y8tl9Wx8oBgJJmyIwV9JBXRFaSgyNIKo6zav2eP+ppNMB6vP5QCZaXLGHq5zvN/cLs6yBaDgVdLnYPGd0RBLMPytPO86UbSPao4RLiIEIDtmvmjbT8rL5QqEhTCiooZuQdewaK0ciEmicvTD2vzqbh/YPY8fnBzgR2psTIvyri/mgFwdrPw0xWtt/uej3zUFPlvUES/a5KXwSaLo6peBNMwY4Kd0xr163rjkwOw==";  
//        String iv="zLWvXQU8fqTuWzBoclEwig==";  
//        String sessionKey = "MvSk7IJ+kZNQoJix5qsmQ==";  
//        toStr(sessionKey,encryptedData,iv);  
    }  
    private static void  toStr(String sessionKey,String  encryptedData ,String iv) throws Exception{  
        byte[] sessionKeyBy = BASE64.decryptBASE64(sessionKey.getBytes("UTF-8"));
        byte[] encryptedDataBy = BASE64.decryptBASE64(encryptedData.getBytes("UTF-8"));  
        byte[] ivBy = BASE64.decryptBASE64(iv.getBytes("UTF-8"));  
        byte[] dec = Pkcs7Encoder.decryptOfDiyIV(encryptedDataBy, sessionKeyBy,ivBy);  
        System.out.println(new String(dec,"UTF-8"));
        
		
	}
}
